package com.chainyoung.component_tmperson.ui.adapter;

import android.content.Intent;
import android.support.annotation.Nullable;
import android.view.View;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.chainyoung.common.appcommon.entity.HdWalletCache;
import com.chainyoung.common.appcommon.entity.HdWalletTokenCache;
import com.chainyoung.component_tmperson.R;
import com.chainyoung.component_tmperson.ui.activity.hdwallet.HdWalletTokenActivity;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.List;

public class HdWalletTokenListAdapter extends BaseQuickAdapter<HdWalletTokenCache,BaseViewHolder> {

    private HdWalletCache hdWallet;

    public HdWalletTokenListAdapter(@Nullable List<HdWalletTokenCache> data, HdWalletCache hdWallet) {
        super(R.layout.layout_list_token_item, data);
        this.hdWallet=hdWallet;
    }

    @Override
    protected void convert(BaseViewHolder helper, final HdWalletTokenCache item) {
        helper.setText(R.id.tv_token_name,item.getTokenName());
        helper.setText(R.id.tv_token_num,new BigDecimal(item.getBalance()).setScale(4, RoundingMode.DOWN).stripTrailingZeros().toPlainString());
        helper.getView(R.id.rl_token).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(mContext, HdWalletTokenActivity.class);
                intent.putExtra("hdWallet", hdWallet);
                intent.putExtra("hdWalletTokenCache",item);
                mContext.startActivity(intent);
            }
        });
    }
}
